package cn.com.mrAdv05;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class ExpenseAccountWritable implements
		WritableComparable<ExpenseAccountWritable> {

	// 两个字段
	private String sno;
	private Double cost;

	public String getSno() {
		return sno;
	}

	public Double getCost() {
		return cost;
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeUTF(sno);
		out.writeDouble(cost);
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		this.sno = in.readUTF();
		this.cost = in.readDouble();
	}

	@Override
	public int compareTo(ExpenseAccountWritable other) {
		// if(this.sno.compareTo(other.sno) != 0) {
		// return this.sno.compareTo(other.sno);
		// } else {
		// return this.cost > other.cost ? 1 : (this.cost == other.cost ? 0 :
		// -1) ;
		// }
		return this.sno.compareTo(other.sno) != 0 ? this.sno
				.compareTo(other.sno) : (this.cost > other.cost ? 1
				: (this.cost == other.cost ? 0 : -1));
	}

	public void set(String sno, double cost) {
		this.sno = sno;
		this.cost = cost;
	}

}
